home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / exem.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  2KB  |  88 lines

  1. /*****************************************************************************
  2.  
  3.     ExeM()
  4.  
  5.     This function executes an M command.
  6.     Mq    Execute string in Q-register q
  7.  
  8. *****************************************************************************/
  9.  
  10. #include "zport.h"        /* define portability identifiers */
  11. #include "tecoc.h"        /* define general identifiers */
  12. #include "defext.h"        /* define external global variables */
  13. #include "deferr.h"        /* define identifiers for error messages */
  14.  
  15. DEFAULT ExeM()            /* execute an M command */
  16. {
  17.     DEFAULT status;
  18.  
  19.     DBGFEN(1,"ExeM",NULL);
  20.  
  21.     if (IncCBP() == FAILURE) {        /* if no character after M */
  22.     DBGFEX(1,DbgFNm,"FAILURE, no Q-register specified");
  23.     return FAILURE;
  24.     }
  25.  
  26.     if (FindQR() == FAILURE) {        /* find q-register */
  27.     DBGFEX(1,DbgFNm,"FAILURE, FindQR() failed");
  28.     return FAILURE;
  29.     }
  30.  
  31.     if (QR->Start == NULL) {        /* if q-register is empty */
  32.     DBGFEX(1,DbgFNm,"SUCCESS, Q-register is empty");
  33.     return SUCCESS;
  34.     }
  35.  
  36. /*
  37.  * Save the current execution state and make the text in the Q-register be
  38.  * the command string to execute.
  39.  */
  40.  
  41.     if (PshMac(QR->Start, QR->End_P1) == FAILURE) {
  42.         DBGFEX(1,DbgFNm,"FAILURE, PshMac() failed");
  43.     return FAILURE;
  44.     }
  45.  
  46. /*
  47.  * If the M command is not colon-modified, create a new set of local
  48.  * q-registers and zero them out.
  49.  */
  50.     if ((CmdMod & COLON) == 0) {        /* if not colon-modified */
  51.     QRptr QRp;
  52.     WORD i;
  53.     QRp = (QRptr)ZAlloc(36 * sizeof(struct QReg));
  54.     if (QRp == NULL) {
  55.         ErrMsg(ERR_MEM);
  56.         DBGFEX(3,DbgFNm,"FAILURE");
  57.         return FAILURE;
  58.     }
  59.     MStack[MStTop].QRgstr = QRp;
  60.     for (i = 0; i < 36; ++i, ++QRp) {
  61.         QRp->Start = QRp->End_P1 = NULL;
  62.         QRp->Number = 0;
  63.     }
  64.     }
  65.  
  66. /*
  67.  * execute command string in Q-register
  68.  */
  69.     status = ExeCSt();
  70. #if DEBUGGING
  71.     if (status == FAILURE) {
  72.     DbgFMs(1,DbgFNm,"ExeCSt() failed");
  73.     }
  74. #endif
  75.  
  76. /*
  77.  * restore old execution state
  78.  */
  79.  
  80.     if (PopMac() == FAILURE) {
  81.         DBGFEX(1,DbgFNm,"FAILURE, PopMac() failed");
  82.     return FAILURE;
  83.     }
  84.  
  85.     DBGFEX(1,DbgFNm,(status == FAILURE) ? "FAILURE" : "SUCCESS");
  86.     return status;
  87. }
  88.